#include "StdAfx.h"
#include <MyControls/ListWidget.h>
#include <MyFC/Utility.h>

namespace My {

TestHeader::TestHeader(ListScrollBox & owner) :
	m_Owner(owner)
{
}

void TestHeader::HandlePaint(CDC * pDC, const CRect & rect)
{
	ClipRect cr(this, pDC, rect);

	CRect r(0, 0, GetTotalWidth(), GetHeight());
	r.OffsetRect(- m_Owner.GetOffset().x, 0);
	CBrush b; b.CreateSysColorBrush(COLOR_BTNFACE);
	pDC->FillRect(&r, &b);
	CBrush blue(RGB(0, 0, 255));
	pDC->FrameRect(&r, &blue);
}

TestList::TestList(ListScrollBox & owner) :
	m_Owner(owner)
{
}

void TestList::HandlePaint(CDC * pDC, const CRect & rect)
{
	ClipRect cr(this, pDC, rect);

	CRect r(0, 0, GetTotalWidth(), GetTotalHeight());
	r.OffsetRect(- m_Owner.GetOffset());
	CBrush b; b.CreateSysColorBrush(COLOR_BTNFACE);
	pDC->FillRect(&r, &b);
	CBrush red(RGB(255, 0, 0));
	pDC->FrameRect(&r, &red);
}

// ListScrollBox

ListScrollBox::ListScrollBox() :
	m_Header(* this),
	m_List(* this)
{
	Add(&m_Header);
	Add(&m_List);
	SetAlignment(ALIGN_STRETCH);
}

void ListScrollBox::LayoutControls()
{
	CRect rClient = ClientRect();
	CRect rHeader(rClient);
	rHeader.bottom = rHeader.top + m_Header.GetHeight();
	m_Header.SetBounds(rHeader);
	CRect rList(rClient);
	rList.top = rHeader.bottom;
	m_List.SetBounds(rList);
}


CSize ListScrollBox::GetPreferredContentSize() const
{
	return CSize(m_List.GetTotalWidth(),
		m_Header.GetHeight() + m_List.GetTotalHeight());
}

} // My